package export.pet
{
	import base.*;
	
	import com.dusk.util.ResUtil;
	import com.game.data.vo.PetDataVO;
	import com.greensock.*;
	
	import export.bullet.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class PetHorse4 extends BasePet
	{
		
		public function PetHorse4(param1:BaseHero, param2:PetDataVO)
		{
			super(param1, param2);
			this.horizonSpeed = 5;
			this.attackBackInfoDict["hit1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [6, -5],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackBackInfoDict["hit2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 24,
				"power"          : 12,
				"attackKind"     : "magic",
				"addEffect"      : [{
					"name": BaseAddEffect.ICE,
					"time": gc.frameClips * 2
				}]
			};
			this.attackBackInfoDict["hit3"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit4"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit5_1"] = {
				"hitMaxCount"    : 1,
				"attackBackSpeed": [0, 0],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit5_2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [0, 0],
				"attackInterval" : 12,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.setAction("idle");
			this.skillCD1 = [gc.frameClips * 4, gc.frameClips * 8];
			this.skillCD2 = [gc.frameClips * 6, gc.frameClips * 10];
			this.skillCD3 = [gc.frameClips * 8, gc.frameClips * 15];
			this.skillCD4 = [gc.frameClips * 30, gc.frameClips * 60];
		}
		
		private var skill1Release:Boolean = false;
		
		override protected function initBBDC():void
		{
			var _loc1_:Object = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("PetHorseBmd4");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 200, 200, new Point(0, 0));
				bbdc.setOffsetXY(1, -25);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 10], [2, 2, 20], [15], [2, 2, 1, 1, 10], [2, 2, 20], [2, 2, 10]]);
				bbdc.setFrameCount([6, 4, 1, 5, 3, 1, 5, 3, 3]);
				bbdc.setEnterFrameCallBack(this.enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("PetHorseBmd4--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite4") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(param1:String):void
		{
			super.setAction(param1);
			var _loc2_:Point = this.bbdc.getCurPoint();
			switch (param1)
			{
				case "idle":
					if (_loc2_.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(param1);
					break;
				case "walk":
					if (_loc2_.y != 1)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(1);
					}
					this.bbdc.setState(param1);
					break;
				case "hurt":
					if (_loc2_.y != 2)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(2);
					}
					this.bbdc.setState(param1);
					break;
				case "hit1":
					if (_loc2_.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(param1);
					break;
				case "hit2":
					if (_loc2_.y != 5)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(5);
					}
					this.bbdc.setState(param1);
					break;
				case "hit3":
					if (_loc2_.y != 6)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(6);
					}
					this.bbdc.setState(param1);
					break;
				case "hit4":
					if (_loc2_.y != 7)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(7);
					}
					this.bbdc.setState(param1);
					break;
				case "hit5":
					if (_loc2_.y != 8)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(8);
					}
					this.bbdc.setState(param1);
					break;
				case "dead":
					if (_loc2_.y != 3)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(3);
					}
					this.bbdc.setState(param1);
			}
		}
		
		override protected function scriptFrameOverFunc(param1:int):void
		{
			var _loc2_:String = this.bbdc.getState();
			switch (_loc2_)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
					break;
				case "idle":
					this.bbdc.setFramePointX(0);
					break;
				case "hit1":
					this.setAction("idle");
					break;
				case "hit2":
					this.setAction("idle");
					break;
				case "hit3":
					this.setAction("idle");
					break;
				case "hit4":
					this.setAction("idle");
					break;
				case "hit5":
					this.setAction("idle");
					break;
				case "hurt":
					this.setStatic();
					this.setAction("idle");
					break;
				case "dead":
					this.destroy();
			}
		}
		
		override protected function enterFrameFunc(param1:Point):void
		{
			var _loc2_:String = this.bbdc.getState();
			var _loc3_:uint = this.getBBDC().getDirect();
			var _loc4_:Point = new Point();
			switch (_loc2_)
			{
				case "hit1":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 20)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 150;
								}
								else
								{
									_loc4_.x = this.x + 150;
								}
								_loc4_.y = this.y - 140;
								this.doHit1(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit2":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 0)
						{
							if (this.bbdc.getCurFrameCount() == 15)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 70;
								}
								else
								{
									_loc4_.x = this.x + 70;
								}
								_loc4_.y = this.y - 85;
								this.doHit2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit3":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 1)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 80;
								}
								else
								{
									_loc4_.x = this.x + 80;
								}
								_loc4_.y = this.y - 45;
								this.doHit3(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit4":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 20)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 55;
								}
								else
								{
									_loc4_.x = this.x + 55;
								}
								_loc4_.y = this.y - 50;
								this.doHit4(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit5":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 55;
								}
								else
								{
									_loc4_.x = this.x + 55;
								}
								_loc4_.y = this.y - 50;
								this.doHit5(_loc3_, _loc4_);
							}
						}
					}
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			return Boolean(this.skill1Release) && getMp() >= this._petInfo.findPetUsedMagic("bd") && Boolean(this._petInfo.findHasStudySkill("bd"));
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			var _loc1_:Number = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
			return _loc1_ >= 50 && _loc1_ <= 100 && getMp() >= this._petInfo.findPetUsedMagic("sp") && Boolean(this._petInfo.findHasStudySkill("sp"));
		}
		
		override protected function beforeSkill3Start():Boolean
		{
			var _loc1_:Number = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
			return _loc1_ <= 250 && getMp() >= this._petInfo.findPetUsedMagic("bz") && Boolean(this._petInfo.findHasStudySkill("bz"));
		}
		
		override protected function beforeSkill4Start():Boolean
		{
			var _loc1_:Number = AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget);
			return this.curAttackTarget != null && getMp() >= this._petInfo.findPetUsedMagic("tmaoyi") && Boolean(this._petInfo.findHasStudySkill("tmaoyi"));
		}
		
		override public function reduceHp(param1:int, param2:Boolean = false):void
		{
			super.reduceHp(param1, param2);
			this.skill1Release = true;
		}
		
		override protected function releSkill1():void
		{
			
			this.faceToTarget();
			this.setAction("hit2");
			this.lastHit = "hit2";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("bd"));
		}
		
		override protected function releSkill2():void
		{
			
			this.faceToTarget();
			this.setAction("hit3");
			this.lastHit = "hit3";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("sp"));
		}
		
		override protected function releSkill3():void
		{
			
			this.faceToTarget();
			this.setAction("hit4");
			this.lastHit = "hit4";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("bz"));
		}
		
		override protected function releSkill4():void
		{
			this.addAoyiBuff();
			this.setInvincible(20);
			
			this.faceToTarget();
			this.setAction("hit5");
			this.lastHit = "hit5";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("tmaoyi"));
		}
		
		override protected function normalHit():void
		{
			this.faceToTarget();
			
			this.setAction("hit1");
			this.lastHit = "hit1";
		}
		
		override public function getRealPower(param1:String, param2:Boolean = true):int
		{
			var _loc3_:Object = null;
			var _loc4_:uint = this.getCriteValue(param2) ? uint(2) : uint(1);
			var _loc5_:uint = uint(this.getMagicAddValue());
			var _loc6_:Number = this.isGXP ? Number(1.2) : Number(1);
			switch (param1)
			{
				case "hit1":
					return (getAtk() + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
				case "hit2":
					_loc3_ = this._petInfo.getPetHarmObj("bd");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit3":
					_loc3_ = this._petInfo.getPetHarmObj("sp");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit4":
					_loc3_ = this._petInfo.getPetHarmObj("bz");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit5_1":
					_loc3_ = this._petInfo.getPetHarmObj("sp");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				case "hit5_2":
					_loc3_ = this._petInfo.getPetHarmObj("bz");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_ * Number(this.hurtBaseEffectRate());
					}
					return 0;
					break;
				default:
					return 0;
			}
		}
		
		override protected function exitFrameFunc(param1:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			if (!this.isBeAttacking())
			{
				super.myIntelligence();
			}
		}
		
		override public function isAttacking():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3" || this.curAction == "hit4" || this.curAction == "hit5";
		}
		
		override protected function isCannotMoveWhenAttackOnFloor():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3" || this.curAction == "hit4" || this.curAction == "hit5";
		}
		
		private function doHit1(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetHorse3Bullet1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit1");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit2(param1:uint, param2:Point):void
		{
			this.setInvincible(15);
			var _loc3_:FollowTargetBullet = new FollowTargetBullet("PetHorse3Bullet2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setIsDestroyWhenOwnerHurt(false);
			_loc3_.setAction("hit2");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
			this.skill1Release = false;
		}
		
		private function doHit3(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetHorse3Bullet3");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit3");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit4(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetHorse3Bullet4");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit4");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit5(param1:uint, param2:Point):void
		{
			var _loc3_:EnemyMoveBullet = null;
			var _loc4_:BaseObject = null;
			trace("dohit5");
			if (this._petInfo.findHasStudySkill("bd"))
			{
				this.attackBackInfoDict["hit5_1"] = {
					"hitMaxCount"    : 1,
					"attackBackSpeed": [0, 0],
					"attackInterval" : 999,
					"power"          : 12,
					"attackKind"     : "magic",
					"addEffect"      : [{
						"name": BaseAddEffect.ICE,
						"time": gc.frameClips * 2
					}]
				};
			}
			else
			{
				this.attackBackInfoDict["hit5_1"] = {
					"hitMaxCount"    : 1,
					"attackBackSpeed": [0, 0],
					"attackInterval" : 999,
					"power"          : 12,
					"attackKind"     : "magic"
				};
			}
			var _loc5_:uint = gc.pWorld.getMonsterArray().length;
			var _loc6_:uint = 0;
			while (_loc6_ < _loc5_)
			{
				_loc4_ = gc.pWorld.getMonsterArray()[_loc5_ - _loc6_ - 1] as BaseObject;
				(_loc3_ = new EnemyMoveBullet("PetHorse4Bullet5")).x = this.x + (_loc5_ / 2 - _loc6_) * 90;
				_loc3_.y = 50;
				_loc3_.setIsDestroyWhenLastFrame(false);
				_loc3_.setDestroyInCount(gc.frameClips * 10);
				_loc3_.setDistance(2000);
				_loc3_.setOwner(this);
				_loc3_.setFuncWhenHitTarget(this.hit5Hit);
				_loc3_.setDirect(0);
				if (this._petInfo.findHasStudySkill("sp"))
				{
					_loc3_.setSpeed(0, 1);
					_loc3_.setSpeedAdd(0, 1);
					_loc3_.setMoveTarget(_loc4_);
				}
				else
				{
					_loc3_.setSpeed(0, 1);
					_loc3_.setSpeedAdd(0, 1);
				}
				_loc3_.setAction("hit5_1");
				gc.gameScene.addChild(_loc3_);
				this.magicBulletArray.push(_loc3_);
				_loc6_++;
			}
		}
		
		private function hit5Hit(param1:BaseBullet):void
		{
			var b:SpecialEffectBullet = null;
			var bb:BaseBullet = param1;
			if (this._petInfo.findHasStudySkill("bz"))
			{
				if (this._petInfo.findHasStudySkill("bd"))
				{
					TweenMax.delayedCall(1.9, function (param1:PetHorse4, param2:BaseBullet):*
					{
						var _loc3_:SpecialEffectBullet = null;
						if (!param1.isDead())
						{
							_loc3_ = new SpecialEffectBullet("PetHorse4Bullet5Explode");
							_loc3_.x = param2.x;
							_loc3_.y = param2.y;
							_loc3_.setOwner(param1);
							_loc3_.setDirect(0);
							_loc3_.setAction("hit5_2");
							gc.gameScene.addChild(_loc3_);
							param1.magicBulletArray.push(_loc3_);
						}
					}, [this, bb]);
				}
				else if (!this.isDead())
				{
					b = new SpecialEffectBullet("PetHorse4Bullet5Explode");
					b.x = bb.x;
					b.y = bb.y;
					b.setOwner(this);
					b.setDirect(0);
					b.setAction("hit5_2");
					gc.gameScene.addChild(b);
					this.magicBulletArray.push(b);
				}
			}
		}
	}
}
